package cn.autumnorange.app.common.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * Copyright © 2018 eSunny Info. Tech Ltd. All rights reserved.
 *
 * @title: ResultDto.java @Package: com.yulece.common.utils
 * @author: wangyichao@yulece.com
 * @date: 创建时间2018年5月1日 - 下午4:48:02
 * @version: 1.0
 */
// ResponseEntity旨在表示整个HTTP响应。您可以控制其中的所有内容：状态码，标头和正文。
//
// @ResponseBody是HTTP响应正文的标记，并@ResponseStatus声明HTTP响应的状态代码。
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultDto<T> {

  private int status;
  private String message;
  private T data;
  private String path;
  private String error;
  private long timestamp = System.currentTimeMillis();

  public ResultDto() {}

  public ResultDto(int status, T data, String message, String path, Long timestamp, String error) {
    this.status = status;
    this.message = message;
    this.data = data;
    this.path = path;
    if (timestamp != null) {
      this.timestamp = timestamp;
    }
    this.error = error;
  }

  public String getPath() {
    return path;
  }

  public void setPath(String path) {
    this.path = path;
  }

  public int getStatus() {
    return status;
  }

  public void setStatus(int status) {
    this.status = status;
  }

  public String getError() {
    return error;
  }

  public void setError(String error) {
    this.error = error;
  }

  public long getTimestamp() {
    return timestamp;
  }

  public void setTimestamp(long timestamp) {
    this.timestamp = timestamp;
  }

  public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
    this.message = message;
  }

  public T getData() {
    return data;
  }

  public void setData(T data) {
    this.data = data;
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createResult() {
    return new ResultDto();
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createResult(
      int status, T data, String message, String path, Long timestamp, String error) {
    return new ResultDto(status, data, message, path, timestamp, error);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createDataResult(T data) {
    return createResult(200, data, null, null, null, null);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createMessageResult(String message) {
    return createResult(200, null, message, null, null, null);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createPathResult(String path) {
    return createResult(200, null, path, null, null, null);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createDataMessageResult(T data, String message) {
    return createResult(200, data, message, null, null, null);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createDataMessagePathResult(T data, String message, String path) {
    return createResult(200, data, message, path, null, null);
  }
}
